using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

public class ScenesChangeManager : SingletonPattern<ScenesChangeManager>
{
    
    public void LoadScene(string name,UnityAction fun)
    {
        SceneManager.LoadScene(name);
        fun.Invoke();
    }

    public void LoadSceneAsync(string name, UnityAction action)
    {
        PublicMonoManager.Instance.StartCoroutine(RealLoadSceneAsync(name,action));
    }

    private IEnumerator RealLoadSceneAsync(string name, UnityAction action)
    {
        AsyncOperation aysncOperation = SceneManager.LoadSceneAsync(name);
        while (!aysncOperation.isDone)
        {
            //EventHub.Instance.EventTrigger("Loading", aysnOperation.progress);
            yield return aysncOperation.progress;
        }

        yield return aysncOperation;
        action.Invoke();

    }
}
